package cn.i7baozh.boot.learn.bean;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 */
@Slf4j
@Component
@Order(-1)//值越小越提前加载
public class BeanLineRunner implements CommandLineRunner {

    @Autowired(required = false)
    private MyTestBean myTestBean;

    @Autowired(required = false)
    private MyTestBean2 myTestBean2;
    @Override
    public void run(String... args) throws Exception {
        //myTestBean 是空，虽然类上有@Component注解，但是在MyBeanDefinitionRegistryPostProcessor将其移除了，所以为空
        log.info("bean1是否为空?  {}", myTestBean == null);
        //myTestBean2不是空，在MyBeanDefinitionRegistryPostProcessor中手动注册了
        log.info("bean2是否为空?  {}", myTestBean2 == null);
        if (myTestBean2 != null) {
            myTestBean2.print();
        }
    }
}
